package com.hskn.hss.module.tlbind.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.hskn.hss.core.controller.BaseController;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tlbind.service.ITlBindService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/hss/tlbind")
public class TlBindController extends BaseController {
    @Autowired
    ITlBindService tlBindService;

    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            Integer pageSize = params.getInteger("size");
            Integer pageNum = params.getInteger("page");
            Page page = startPage(pageNum, pageSize);
            return AjaxResult.success(getDataTable(tlBindService.getobjList(params),page.getTotal()));
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败");
        }
    }

    @RequestMapping(value = "getobjSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getobjSelectList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return AjaxResult.success(tlBindService.getobjSelectList(params));
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败");
        }
    }
}
